/**
 * 基于微擎请求接口再次封装，简化流程方便进行async await同步化操作
 * 
 * @param {String} url 请求接口  
 * @param {String} method 请求方法 
 * @param {Object} header 请求头
 * @param {Object} data 携带数据 
 * @param {success} resolve 携带成功后的数据 
 * @param {fail} reject 携带失败后的数据 
 * 
 * @return {Any} data 返回任意数据 
 * 
 * 
 * @example 
 * 
 * async getIndex(){
 *	 const indexInfo = await this.$http({
 *		url:'xxx',
 *      data:{}
 *	 });
 * 	console.log('indexInfo',indexInfo);
 * }
 * 
 * */
import {
	request
} from "./util.js";

// const domain = "locationhost";

export default ({
	url,
	method,
	data,
	header,
	success,
	fail
}) => {
	return new Promise((resolve, reject) => {
		try {
			request({
				url,
				method: method ? method : "GET",
				data: data ? data : {},
				header: header ? header : {
					"Content-Type": "application/json"
				},
				complete: (res) => {
					resolve(res.data);
				}
			});
		} catch (e) {
			throw new Error(`请求接口未填写，请检查!${url}`);
		}
	});
}
